import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.graph.Vertex;
import com.arcadedb.query.sql.executor.ResultSet;
import nju.hjh.arcadedb.timeseries.statistics.LongStatistics;
import nju.hjh.arcadedb.timeseries.statistics.StringStatistics;
import nju.hjh.arcadedb.timeseries.TimeseriesEngine;
import nju.hjh.arcadedb.timeseries.exception.TimeseriesException;

public class TimeseriesPersistentTest {
    public static void main(String[] args) {
        DatabaseFactory dbf = new DatabaseFactory("./databases/carTsTest4");
        Database database;
        if (!dbf.exists()){
            database = dbf.create();
        }else {
            database = dbf.open();
        }

        final String vertexType="car";

        TimeseriesEngine ts = new TimeseriesEngine(database);

        ResultSet rs = database.query("SQL", "select from car where carId='冀A4D159-1'");
        if (rs.hasNext()){
            Vertex car = rs.next().getVertex().orElseGet(() -> null);
            if (car != null){
                try {
                    LongStatistics expiredStat = (LongStatistics) ts.aggregativeQuery(car, "expired", 1635700891000L, Long.MAX_VALUE);
                    StringStatistics passidStats = (StringStatistics) ts.aggregativeQuery(car, "passId", 1635700891000L, Long.MAX_VALUE);
                    System.out.println(expiredStat.firstTime+": expired= "+expiredStat.firstValue);
                    System.out.println(passidStats.firstTime+": passid= "+passidStats.firstValue);
                } catch (TimeseriesException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        database.close();
    }
}
